package com.ikun.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.ikun.entity.CleaningOrders;
import com.ikun.service.CleaningOrdersService;
import com.ikun.util.Result;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * @ClassName: CleaningOrdersController
 * @Author: 吴思伟
 * @CreateTime: 2025-03-26 10:08
 * @Description: 保洁订单管理相关
 */

@Controller
@RequestMapping("/cleaningOrders")
@Tag(name = "保洁订单管理相关", description = "保洁订单管理相关")
public class CleaningOrdersController {
    @Autowired
    private CleaningOrdersService cleaningOrdersService;

    @GetMapping("/assignedOrders")
    @ResponseBody
    public Result showAssignedOrders() {
        return Result.success(cleaningOrdersService.findAssignedOrders());
    }

    @GetMapping("/completedOrders")
    @ResponseBody
    public Result showCompletedOrders() {
        return Result.success(cleaningOrdersService.findCompleted());
    }

    @GetMapping("/work-orders")
    @ResponseBody
    public Result getPendingOrders(@RequestParam("staff_id") Integer staffId) {
        return cleaningOrdersService.getPendingOrders(staffId);
    }

    @GetMapping("/complete")
    @Operation(summary = "标记保洁工单为已完成状态", description = "根据工单ID将保洁工单标记为已完成状态")
    @ResponseBody
    public Result markOrderAsCompleted(String orderId, String staffId) {
        return cleaningOrdersService.markOrderCompleted(orderId, staffId);
        // return Result.success("success");
    }

    @PostMapping("/assign")
    @Operation(summary = "分配保洁工单", description = "根据工单ID将保洁工单分配给指定的保洁员")
    @ResponseBody
    public Result getPendingOrders(@RequestParam("staff_id") Integer staffId,
        @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        return cleaningOrdersService.getPendingOrders(staffId);
    }

    @PostMapping("/create")
    @ResponseBody
    public Result createCleaning(@RequestBody CleaningOrders cleaningOrders) {
        return Result.success(cleaningOrdersService.createCleaning(cleaningOrders));
    }

    @GetMapping("/allWorkOrdersByMangerId")
    @ResponseBody
    public Result getAllWorkOrdersByMangerId(Integer mangerId) {
        return Result.success(cleaningOrdersService.getAllWorkOrdersByMangerId(mangerId));
    }

    @PostMapping("/assignStaff")
    @ResponseBody
    @Operation(summary = "分配保洁人员", description = "根据工单ID分配保洁人员")
    public Result assignStaff(@RequestParam("orderId") Integer orderId, @RequestParam("staffId") Integer staffId) {
        return Result.success(cleaningOrdersService.assignStaff(orderId, staffId));
    }

}
